<script setup lang="ts">
import { ref, onMounted, reactive } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { Get_stats } from '@/api/index'
const router = useRouter();
// 导航回退
const onClickLeft = () => {
    router.push('/home')
}
const data: any = ref([]) //second_hand_house
const value = ref('');
const page = JSON.parse(localStorage.getItem('user') as string).second_hand_house;
onMounted(async () => {
    let res = await Get_stats('1', '10')
    console.log(res);
    res.data.data.forEach((t: any) => {
        data.value.push({
            id: t.id,
            name: t.name,
            price: t.price,
            resident: t.resident,
            extent: t.extent,
            house_type: t.house_type,
            ll: t.ll,
            img: t.img,
        })
    });
})
// 切换地址
const show = ref(false)
const select = ref('北京');
const open = () => {
    show.value = !show.value;
}
// 下拉菜单数据
const range = reactive([{
    value: 0,
    text: "全部"
},
{
    value: 1,
    text: "北京"
},
{
    value: 2,
    text: "上海"
},
{
    value: 3,
    text: "天津"
},
{
    value: 4,
    text: "重庆"
},
]);
// 下拉框触发的change事件
const valueClick = (text: string) => {
    select.value = text;
    show.value = !show.value;
};
// 搜索
const input: any = ref(null);
const onSearch = (value: string) => {
    const newData = data.value.filter((t: any) => t.name.includes(value))
    data.value = newData
}
const clear = async() => {
    let res = await Get_stats('1', '10')
    console.log(res);
    res.data.data.forEach((t: any) => {
        data.value.push({
            id: t.id,
            name: t.name,
            price: t.price,
            resident: t.resident,
            extent: t.extent,
            house_type: t.house_type,
            ll: t.ll,
            img: t.img,
        })
    });
}

</script>
<template>
    <div class="box">
        <header>
            <van-icon name="arrow-left" class="icon" @click="onClickLeft" />
            成交战绩
        </header>
        <main>
            <div>
                <div class="top">
                    <div>
                        <text @click='open'>{{ select }} ▼</text>
                        <div class="tan" v-show="show">
                            <div v-for="(item, index) in range" :key="index" @click="valueClick(item.text)">{{ item.text }}
                            </div>
                        </div>
                    </div>
                    &emsp;
                    <div>
                        <van-search class="input" @clear="clear" @search="onSearch" v-model="value" placeholder="请输入搜索关键词" />
                    </div>
                </div>
                <div class="content" v-if="data.length > 0">
                    <div class="dl" v-for="(item, index) in data" :key="index">
                        <div class="dt">
                            <img style="width: 40vw;" :src="item.img" />
                        </div>
                        <div class="dd">
                            <div class="dd-title">
                                {{ item.name }}
                            </div>
                            <div class="dd-introduce">
                                {{ item.ll }}平/{{ item.house_type }} 1厅 / {{ item.resident }}
                            </div>
                            <div class="dd-price">
                                {{ item.price }}万 <text style="font-size: 10px; color: #000;">{{ item.extent }}元/m²</text>
                            </div>
                            <div class="dd-div">
                                小区
                            </div>
                        </div>
                    </div>
                </div>
                <div class="content" v-else>
                    <van-empty description="么有数据" />
                </div>
            </div>
        </main>
    </div>
    <van-floating-bubble icon="wap-home-o" @click="onClickLeft" />
</template>

<style scoped lang="scss">
* {
    margin: 0;
    padding: 0;
}

.box {
    width: 100vw;
    height: 100vh;

    header {
        width: 100vw;
        height: 50px;
        background-color: #2391f9;
        display: flex;
        justify-content: center;
        align-items: center;
        color: #fff;
        position: relative;

        .icon {
            position: absolute;
            top: 50%;
            left: 10%;
            transform: translate(-50%, -50%);
        }
    }

    main {
        width: 100%;
        height: calc(100% - 50px);
        padding: 0 10px;
        box-sizing: border-box;
        overflow: auto;

        .top {
            width: 100%;
            height: 35px;
            display: flex;
            line-height: 35px;
            padding: 0 10px;
            box-sizing: border-box;
            position: sticky;
            top: 0px;
            background: #fff;



            .tan {
                width: 50px;
                text-align: center;
                box-sizing: border-box;
                line-height: 25px;
                padding: 5px;
                border-radius: 5px;
                background: #fcfcfc;
                box-shadow: 0 0 2px 2px #ccc;
                position: absolute;
                top: 28px;
                left: 10px;
            }

            ::v-deep .input {
                width: 110%;
            }

        }



        .content {
            width: 100%;
            height: calc(100% - 35px);

            .dl {
                width: 100%;
                display: flex;
                height: 120px;
                overflow: hidden;
                margin-top: 10px;
                background: #fcfcfc;
                padding: 10px;
                box-sizing: border-box;
                border-radius: 5px;

                .dd {
                    margin-left: 10px;
                    padding: 5px;
                    line-height: 22px;
                }

                .dd-title {
                    width: 5 0vw;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    font-weight: bold;
                }

                .dd-introduce {
                    font-size: 12px;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                    overflow: hidden;
                }

                .dd-price {
                    font-size: 14px;
                    color: rgb(255, 153, 0);
                }

                .dd-div {
                    font-size: 14px;
                }

                .dd-div {
                    display: inline-block;
                    padding: 2px 10px;
                    background: #f0f0f0;
                    border-radius: 5px;
                }
            }
        }
    }
}
</style>